package com.example.lxj.judicial.service.impl;

import java.util.List;

import cn.hutool.core.date.DateUtil;
import com.example.lxj.LegalCase.entity.TbCaseRegistration;
import com.example.lxj.LegalCase.mapper.TbCaseRegistrationMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.example.lxj.judicial.mapper.TbIdentificationPlanMapper;
import com.example.lxj.judicial.entity.TbIdentificationPlan;
import com.example.lxj.judicial.service.ITbIdentificationPlanService;

/**
 * 鉴定方案Service业务层处理
 *
 * @author lxj
 * @date 2024-10-24
 */
@Service
public class TbIdentificationPlanServiceImpl implements ITbIdentificationPlanService {
    @Autowired
    private TbIdentificationPlanMapper tbIdentificationPlanMapper;

    @Autowired
    private TbCaseRegistrationMapper tbCaseRegistrationMapper;

    /**
     * 查询鉴定方案
     *
     * @param id 鉴定方案主键
     * @return 鉴定方案
     */
    @Override
    public TbIdentificationPlan selectTbIdentificationPlanById(Long id) {
        return tbIdentificationPlanMapper.selectTbIdentificationPlanById(id);
    }

    /**
     * 查询鉴定方案列表
     *
     * @param tbIdentificationPlan 鉴定方案
     * @return 鉴定方案
     */
    @Override
    public List<TbIdentificationPlan> selectTbIdentificationPlanList(TbIdentificationPlan tbIdentificationPlan) {
        return tbIdentificationPlanMapper.selectTbIdentificationPlanList(tbIdentificationPlan);
    }

    /**
     * 新增鉴定方案
     *
     * @param tbIdentificationPlan 鉴定方案
     * @return 结果
     */
    @Override
    public int insertTbIdentificationPlan(TbIdentificationPlan tbIdentificationPlan) {
        tbIdentificationPlan.setCreateTime(DateUtil.date());
        int i = tbIdentificationPlanMapper.insertTbIdentificationPlan(tbIdentificationPlan);
        if (0 < i) {
            // 开始更改案件状态
            TbCaseRegistration tbCaseRegistration = new TbCaseRegistration();
            tbCaseRegistration.setId(tbIdentificationPlan.getCaseId());
            tbCaseRegistration.setStatus("2");
            return tbCaseRegistrationMapper.updateTbCaseRegistration(tbCaseRegistration);
        } else {
            return -1;
        }
    }

    /**
     * 修改鉴定方案
     *
     * @param tbIdentificationPlan 鉴定方案
     * @return 结果
     */
    @Override
    public int updateTbIdentificationPlan(TbIdentificationPlan tbIdentificationPlan) {
        tbIdentificationPlan.setUpdateTime(DateUtil.date());
        return tbIdentificationPlanMapper.updateTbIdentificationPlan(tbIdentificationPlan);
    }

    /**
     * 批量删除鉴定方案
     *
     * @param ids 需要删除的鉴定方案主键
     * @return 结果
     */
    @Override
    public int deleteTbIdentificationPlanByIds(Long[] ids) {
        return tbIdentificationPlanMapper.deleteTbIdentificationPlanByIds(ids);
    }

    /**
     * 删除鉴定方案信息
     *
     * @param id 鉴定方案主键
     * @return 结果
     */
    @Override
    public int deleteTbIdentificationPlanById(Long id) {
        return tbIdentificationPlanMapper.deleteTbIdentificationPlanById(id);
    }
}
